<?php

namespace App\Services\Tools;

use App\Response\Response;
use Illuminate\Http\Request;
use App\Exceptions\BasicException;

use Illuminate\Support\Facades\Log;

/**
 * 高德地图相关服务
 */
class AmapService
{
    protected $appKey;

    public function __construct()
    {
        $this->appKey = env('AMAP_APP_KEY');
    }

    /**
     * IP定位接口
     * @param $ip
     * @param int $timeout
     * @return mixed
     * @throws BasicException
     */
    public function getRegionByIp($ip, $timeout = 1)
    {
        $url = 'https://restapi.amap.com/v3/ip';
        $params = [
            "key" => $this->appKey,
            "ip"  => $ip,
        ];
        return CurlService::curl_get($url, $params, $timeout);
    }
}

